home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 20 / Cream of the Crop 20 (Terry Blount) (1996).iso / os2 / xdsn217.zip / BIN / fatfs.cmd next >
OS/2 REXX Batch file  |  1996-07-08  |  3KB  |  126 lines

  1. /*  */
  2.  
  3. Call RxFuncAdd 'SysLoadFuncs','RexxUtil','SysLoadFuncs'
  4. Call SysLoadFuncs
  5.  
  6. parse arg action
  7.  
  8. if action = '+' then nop
  9. else if action = '-' then nop
  10. else do
  11.   say 'Usage: FATFS +|-'
  12.   exit
  13. end
  14.  
  15. parse source . . home
  16. home = left(home,lastpos('\',home)-1)      /* Strip "\<cmd-name>" */
  17. home = left(home,lastpos('\',home)-1)      /* Strip "\BIN" */
  18.  
  19. ext = 'def'
  20. call Rename
  21. ext = 'odf'
  22. call Rename
  23.  
  24. call Toggle
  25. exit
  26.  
  27. Toggle:
  28.   cfg = home'\bin\xc.cfg'
  29.   rc = stream(cfg,'c','open read')
  30.   if rc <> 'READY:' then do
  31.     say 'Error opening 'name': 'rc
  32.     exit
  33.   end
  34.   
  35.   fatfs = action'fatfs % Do not toggle this option! Instead, use the FATFS.CMD script'
  36.   
  37.   newcfg = SysTempFileName(home'\bin\xc.???')
  38.   rc = stream(newcfg,'c','open write')
  39.   
  40.   do while lines(cfg) <> 0
  41.     line = linein(cfg)
  42.     newline = space(line,0)||' '
  43.     if (substr(newline,2,5) = 'fatfs') & ,
  44.        (pos(left(newline,1),'+-') > 0) & ,
  45.        (pos(substr(newline,7,1),'+-% ') > 0) then do
  46.        line = fatfs
  47.        fatfs = ''
  48.     end
  49.     call lineout newcfg, line
  50.   end
  51.   
  52.   if fatfs <> '' then
  53.     call lineout newcfg, fatfs
  54.   
  55.   rc = stream(cfg,'c','close')
  56.   rc = stream(newcfg,'c','close')
  57.   
  58.   '@del 'cfg
  59.   '@ren 'newcfg' xc.cfg'
  60.  
  61.   return
  62.  
  63. Rename:
  64.   call SysFileTree home'\*.'ext, file, 's'
  65.   do i = 1 to file.0
  66.     parse var file.i date time size attrib name
  67.     name = strip(name)
  68.     if pos('SAMPLES',name) <> 0 then iterate
  69.   
  70.     call LocateModuleId
  71.     if module = '' then do
  72.       say 'Failed to locate module id in' name
  73.       exit
  74.     end
  75.     old = substr(name,lastpos('\',name)+1)
  76.     old = substr(old,1,lastpos('.',old)-1)
  77.   
  78.     select
  79.     when action = '-' then do
  80.       new = module
  81.       if translate(old) <> translate(strip(substr(module,1,8))) then do
  82.         say 'Name inconsistency: ' old module
  83.         exit
  84.       end
  85.     end
  86.     when action = '+' then do
  87.       new = strip(substr(module,1,8))
  88.       if translate(old) <> translate(module) then do
  89.         say 'Name inconsistency: ' old module
  90.         exit
  91.       end
  92.     end
  93.     otherwise iterate
  94.     end
  95.   
  96.     say old '->' new
  97.     '@ren' name new'.'ext
  98.     sym = home'\SYM\'old'.sym'
  99.     if stream(sym,'c','query exists') <> '' then
  100.       '@ren' sym new'.sym'
  101.   
  102.   end
  103.   return
  104.  
  105. LocateModuleId:
  106.   rc = stream(name,'c','open read')
  107.   if rc <> 'READY:' then do
  108.     say 'Error opening 'name': 'rc
  109.     exit
  110.   end
  111.   module = ''
  112.   do while lines(name) <> 0
  113.     line = linein(name)
  114.     if word(line,1) = 'DEFINITION' then do
  115.       module = word(line,2)
  116.       if module = 'MODULE' then do
  117.         module = word(line,3)
  118.         if substr(module,1,1) = '[' then module = word(line,4)
  119.       end
  120.       module = strip(translate(module,,';'))
  121.       leave
  122.     end
  123.   end
  124.   rc = stream(name,'c','close')
  125.   return
  126.